// const { batchDisableRemoteMethod } = require('../utils/tool.ts');
const qs = require('qs');
const app = require('../../server/server');
const sqlConfig = require('../../server/boot/sqlConnector');
const dbs = app.dataSources.sqldb;
module.exports = function (CoffeeShop) {
  CoffeeShop.status = function (id, options) {
    let currentDate = new Date();
    let currentHour = currentDate.getHours();
    let OPEN_HOUR = 6;
    let CLOSE_HOUR = 20;
    console.log('Current hour is %d', currentHour, id, options);
    let response;
    if (currentHour > OPEN_HOUR && currentHour < CLOSE_HOUR) {
      response = 'We are open for business.';
    } else {
      response = 'Sorry, we are closed. Open daily from 6am to 8pm.';
    }
    // cb(null, response);
    return Promise.resolve(response + id);
  };
  CoffeeShop.shopLists = async function (options) {
    // const find = async () => {
    //   return dbs.connector.execute('select * from CoffeeShop', [], options, function (err, list) {
    //     if (err) throw err;
    //     console.log('list', JSON.parse(JSON.stringify(list)));
    //     const len = list.length;

    //     return Promise.resolve(len);
    //   });
    // };
    // console.log(await find(), 'results');
    return new Promise(async (resolve, reject) => {
      dbs.connector.execute('select * from CoffeeShop where city=?', ['beijing'], function (err, list) {
        if (err) reject(err);
        // console.log('list', JSON.parse(JSON.stringify(list)));
        const resLists = JSON.parse(JSON.stringify(list));
        resolve({
          data: resLists,
          code: 0,
          msg: 'success',
        });
      });
    });
  };
};
